#include<iostream>

using namespace std;


int getmid(int* a, int left, int right)
{
	int mid = (left + right) / 2;
	if (a[left] > a[mid])
	{
		if (a[mid] > a[right])
		{
			return mid; 
		} 
		else if (a[right] > a[left])     
		{
			return left;
		}
		else
			return right; 
	}
	else//a[left]<a[mid]
	{
		if (a[mid] < a[right])
		{ 
			return mid; 
		}
		else if (a[right] < a[left])
		{
			return left; 
		}
		else
			return right;
	}
}


int main()
{
	int a[] = { 5,4,6,8,1,2 };
	int midi = getmid(a, 3, 5);   
	cout << midi << endl; 
	return 0;
}
